<%--
  Created by IntelliJ IDEA.
  User: last
  Date: 2025/5/20
  Time: 17:34
--%>
<%@ page contentType="text/html; charset=UTF-8" language="java" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.List" %>
<%@ page import="static java.lang.Thread.sleep" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>处理取票请求</title>
    <link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
    <link rel="stylesheet" href="css/ticketCollection.css">
</head>
<body>
<%@ include file="adminNavbar.jsp" %>

<!-- 添加操作结果提示 -->
<%
    String message = (String) session.getAttribute("approvalMessage");
    if (message != null) {
%>
<div class="w-full px-4 py-2 <%= message.contains("成功") ? "bg-green-100 text-green-700" : "bg-red-100 text-red-700" %>">
    <%= message %>
</div>
<%
        try {
            sleep(2000);// 显示1秒后自动消失
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        session.removeAttribute("approvalMessage");  // 显示后清除
    }
%>

<div class="collection-container mt-16">
    <h1 class="text-3xl font-bold text-gray-800 mb-6 text-center">待审核取票请求</h1>

    <div class="w-full">
        <table class="min-w-full divide-y divide-gray-200">
            <thead class="bg-gray-50">
            <tr>
                <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">请求ID</th>
                <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">机票ID</th>
                <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">订单号</th>
                <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">用户ID</th>
                <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">座位</th>
                <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">操作</th>
            </tr>
            </thead>
            <tbody class="bg-white divide-y divide-gray-200">
            <%
                List<Map<String, String>> pendingRequests = (List<Map<String, String>>) application.getAttribute("pendingTicketRequests");
                if (pendingRequests != null) {
                    for (Map<String, String> stringMap : pendingRequests) {
            %>
            <tr>
                <td class="px-6 py-4"><%= stringMap.get("id") %></td>
                <td class="px-6 py-4"><%= stringMap.get("ticketId") %></td>
                <td class="px-6 py-4"><%= stringMap.get("oid") %></td>
                <td class="px-6 py-4"><%= stringMap.get("uid") %></td>
                <td class="px-6 py-4"><%= stringMap.get("seat") %></td>
                <td class="px-6 py-4">
                    <form action="TicketApprovalServlet" method="post" class="inline-block">
                        <input type="hidden" name="requestId" value="<%= stringMap.get("id") %>">
                        <input type="hidden" name="action" value="approve">
                        <button type="submit" class="bg-green-500 px-4 py-2 text-sm rounded">批准</button>
                    </form>
                    <form action="TicketApprovalServlet" method="post" class="inline-block ml-2">
                        <input type="hidden" name="requestId" value="<%= stringMap.get("id") %>">
                        <input type="hidden" name="action" value="reject">
                        <button type="submit" class="bg-red-500 px-4 py-2 text-sm rounded">拒绝</button>
                    </form>
                </td>
            </tr>
            <% }} %>
            </tbody>
        </table>
    </div>
</div>
</body>
</html>